package chapter01;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class InterruptTest {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            try {
                Thread.sleep(2000);// 线程会进入 TIMED_WAITING 状态
                // sleepp运行后恢复RUNNABLE状态
                log.info("try中睡眠结束后的代码执行...");
            } catch (InterruptedException e) {
                // 睡眠被打断会被执行
                log.info("weak up...");
                // ...
            }
            log.info("打断后的后续代码会被执行");
        }, "t1");
        t1.start();
        Thread.sleep(1000);
        t1.interrupt();// 只对sleep有效
        System.out.println(t1.getState());
    }
}
